//
//  SportSwingCell.m
//  CoolTennisBall
//
//  Created by Coollang on 16/8/15.
//  Copyright © 2016年 CoolLang. All rights reserved.
//

#import "SportSwingCell.h"
#import "SportRecordItem.h"
#import "NSAttributedString+RichText.h"
#import "CommunicationManager.h"

@interface SportSwingCell ()
@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet UIView *leftBgView;
@property (weak, nonatomic) IBOutlet UILabel *monthAndDayLabel;

@property (weak, nonatomic) IBOutlet UILabel *dayThLabel;

@property (weak, nonatomic) IBOutlet UILabel *sportTimeLbael;
@property (weak, nonatomic) IBOutlet UILabel *hitBallNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *bestServeLabel;

@property (weak, nonatomic) IBOutlet UIView *lineView;

@property (weak, nonatomic) IBOutlet UIView *blackCoverView;


@property (nonatomic, strong) SportRecordItem *sportitem;


@end
@implementation SportSwingCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.bgView.layer.cornerRadius = 3;
    self.bgView.layer.masksToBounds = YES;
    self.bgView.layer.borderWidth = 0.5;
    self.bgView.layer.borderColor = [UIColor colorWithHex:0x7a7b80 alpha:0.4].CGColor;
    self.bgView.layer.shadowOpacity = 0.7;
    self.bgView.layer.shadowRadius = 1;
    self.bgView.layer.shadowColor = kUnSelectedColor.CGColor;
}

- (void)configureWithItem:(SportRecordItem *)item indexDay:(NSInteger)indexDay isUploading:(BOOL)isUploading {
    
    self.sportitem = item;
    
    self.monthAndDayLabel.text = [item monthAndDay];
    
    UIColor *darkTextColor = [UIColor colorWithHex:0x7c7b80];
    UIColor *lightTextColor = [UIColor colorWithHex:0x7c7b80 alpha:0.8];
    UIColor *whiteColor = [UIColor whiteColor];
    
    UIFont *size20Font = SanFranciscoFont(20);//[UIFont fontWithDescriptor:FontDescriptorMedium(20) size:0.0f];
    UIFont *size10Font = MYFONT(10);
    UIFont *size12Font = [UIFont systemFontOfSize:12];
    
    
//    第几天
    if ([NSBundle currentLanguageIsChinese]) {
        NSString *daythString = [NSString stringWithFormat:@"第 %zd 天",indexDay];
        self.dayThLabel.attributedText = [NSAttributedString attributedString:daythString subString:@[@"第", [@(indexDay) stringValue] , @"天"] colors:@[whiteColor, whiteColor, whiteColor] fonts:@[size12Font, size20Font, size12Font]];
    }else {
        NSString *daythString =[NSString stringWithFormat:NSLocalizedString(@"Day %d", nil),indexDay];
        self.dayThLabel.attributedText = [NSAttributedString attributedString:daythString subString:@[NSLocalizedString(@"Day", nil), [@(indexDay) stringValue]] colors:@[whiteColor, whiteColor] fonts:@[size12Font, size20Font]];
    }
    
//    运动时间
    [NSString stringWithFormat:@"%ld",(long)item.exerciseTimeInterval];
    NSString *sportTimeString = [NSString stringWithFormat:@"%zd%@",item.exerciseTimeInterval, NSLocalizedString(@"Unit.Minute", nil)];
    self.sportTimeLbael.attributedText = [NSAttributedString attributedString:sportTimeString subString:@[@(item.exerciseTimeInterval).stringValue, NSLocalizedString(@"Unit.Minute", nil)] colors:@[darkTextColor, lightTextColor] fonts:@[size20Font, size10Font]];
    
//    击球
    NSString *hitBallNumString = [NSString stringWithFormat:@"%ld%@",(long)[item amountOfCount], NSLocalizedString(@"Sport.Unit.Shots", nil)];
    self.hitBallNumLabel.attributedText = [NSAttributedString attributedString:hitBallNumString subString:@[@([item amountOfCount]).stringValue , NSLocalizedString(@"Sport.Unit.Shots", nil)] colors:@[darkTextColor, lightTextColor] fonts:@[size20Font, size10Font]];
//    最佳发球
    CGFloat bestServeSpeed = item.maxSpeed * 1.23;
    if (bestServeSpeed > 0 && bestServeSpeed <= 250) {
   
        NSString *bestServeString = [NSString stringWithFormat:@"%0.f km/h", bestServeSpeed];
        NSString *subStr1 = [NSString stringWithFormat:@"%0.f",bestServeSpeed];
        
        self.bestServeLabel.attributedText = [NSAttributedString attributedString:bestServeString subString:@[subStr1, @"km/h"] colors:@[darkTextColor, lightTextColor] fonts:@[size20Font, size10Font]];
        
    }else {
        self.bestServeLabel.text = @"--";
    }
    
    if (!item.hasUploadSportSessionValues && [CommunicationManager shareInstance].isPeripheralConnectedWithoutAlertView) {
         self.blackCoverView.hidden = NO;
    } else {
        self.blackCoverView.hidden = YES;
    }
    
}

- (void)showlineView:(BOOL)show {
    
    self.lineView.hidden = !show;
}

@end
